package config

import (
	"log"

	"cooke-home/gateway-service/proxy"

	"github.com/hashicorp/consul/api"
)

var ConsulClient *api.Client

// InitConsul 初始化 Consul 客户端
func InitConsul(addr string) {
	config := api.DefaultConfig()
	config.Address = addr

	var err error
	ConsulClient, err = api.NewClient(config)
	if err != nil {
		log.Fatal("Failed to initialize Consul client:", err)
	}

	// 初始化proxy包中的Consul客户端
	proxy.InitConsulClient(ConsulClient)

	log.Println("Consul client initialized successfully")
}
